<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page import="schronisko.*,Users.*,java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="../styles/message.css">
<title>Nowe wiadomosci</title>

</head>
<body>
<% if(session.getAttribute("ID") != null){ %>
	<a href="../admin/messages.jsp"> Powrot do panelu</a>
	<br>
	<br>
	
	<center>
	<h1>Nowe wiadomosci</h1>
		<%
		if((Integer)session.getAttribute("sent") == 1){
			out.println("Pomyslnie wyslano odpowiedz");
			session.setAttribute("sent", 0);
		}
			
			if ((Integer) session.getAttribute("type") == 2 || (Integer) session.getAttribute("type") == 3) {
				response.setContentType("text/html");
				if ((Integer) session.getAttribute("deleted_msg") == 1) {
					out.println("Pomyslnie usunieto wiadomosc<br><br><br>");
					session.setAttribute("deleted_msg", 0);
				} else if ((Integer) session.getAttribute("mark_msg") == 1) {
					out.println("Oznaczono jako przeczytana<br><br><br>");
					session.setAttribute("mark_msg", 0);
				}
				Queries q = new Queries();
				ResultSet r = q.getMessages(0);
				while (r.next()) {
					int ID = r.getInt("ID_msg");
		%>
		<div class="table">
			<div class='ID'>
				<%
					out.println(ID);
				%>
			</div>
			<div class='username'>
				<%
					out.println(r.getString("username"));
				%>
			</div>
			<div class='email'>
				<%
					out.println(r.getString("email"));
				%>
			</div>
			<div class='topic'>
				<%
					out.println(r.getString("topic"));
				%>
			</div>
			<div class='data'>
				<%
					out.println(r.getString("msg"));
				%>
			</div>
			<div class='date'>
				<%
					out.println(r.getDate("date"));
				%>
			</div>
			<div class='delete'>
				<form name='delete' action='../Message' method='post'>
					<input id='id' name='id' type='hidden'
						value="<% out.print(ID); %>"> <input id='type'
						name='type' type='hidden' value='del'> <input
						type='submit' value='Usun'>
				</form>
			</div>
			<div class='reply'>
				<form name='reply' action='../Message' method='post'>
					<input id='email' name='email' type='hidden'
						value='<% out.print(r.getString("email"));%>'> 
						<input
						id='id' name='id' type='hidden' value="<% out.print(ID); %>"><input id='type'
						name='type' type='hidden' value='ans'> <input
						type='submit' value='Odpisz'>
				</form>
			</div>
			<div class='mark'>
				<form name='reply' action='../Message' method='post'>
					<input id='type' name='type' type='hidden' value='mark'> <input
						id='id' name='id' type='hidden' value='<% out.print(ID); %>'>
					<input type='submit' value='Oznacz jako przeczytana'>
				</form>
			</div>
		</div>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<%
			}
			}
}
else {
	out.println("<div class='menu'><b>Sesja wygasla.</b><br> Za 3 sec nastapi przeniesienie do strony logowania <br> Kliknij, jesli nie zadziala:<br> <a href = '../index.jsp'> Wroc do strony glownej</a></div>");
	response.setHeader("Refresh", "3; URL=../index.jsp");
}
		%>
	</center>
</body>
</html>